home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01a.txt / 000035_icon-group-sender _Fri May 26 08:35:41 2000.msg < prev    next >
Internet Message Format  |  2002-01-03  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id IAA02292
  4.     for icon-group-addresses; Fri, 26 May 2000 08:35:31 -0700 (MST)
  5. Message-Id: <200005261535.IAA02292@baskerville.CS.Arizona.EDU>
  6. From: Steve Wampler <swampler@noao.edu>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: CODE() and  @/2
  9. Date: Fri, 26 May 2000 07:54:20 -0700
  10. X-Trace: noao.edu 959352862 96002 140.252.38.6 (26 May 2000 14:54:22 GMT)
  11. X-Complaints-To: abuse@noao.edu
  12. X-Accept-Language: en
  13. To: icon-group@optima.CS.Arizona.EDU
  14. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  15. Status: RO
  16. Content-Length: 3044
  17.  
  18. "F.G. van DORP" wrote:
  19. ...
  20. > Can  somebody please explain the infix @ operator  ?
  21. > The closest I can get  is something like:  @'s first argument gets  pushed
  22. > onto its second argument's  stack  before the latter is activated  (and
  23. > at  this  point my  mind goes  blank...  OK,  so  the  infix is just  a prefix
  24. > @ with &NULL as the first argument, which doesn't help me a lot either).
  25. > Its purpose is apparently  to have co-expressions communicate between
  26. > themselves (thus enabling  them to gang up against the programmer  ?)
  27.  
  28. Think of co-expressions a threads that don't execute simultaneously.
  29. Instead, co-expressions cooperate by explicitly passing control between
  30. them using the @ operator as a "transfer point".  Logically, the CPU resource
  31. is being passed among the co-expressions (remember that Icon's execution
  32. starts in a co-expression, referenced by &main).
  33.  
  34. Now, think of the @ operator from the point of view of the co-expression
  35. that is invoking it - the behavior of the @ is very much like that
  36. co-expression making a function call - execution of the co-expression
  37. (call it "A") is suspended until execution "returns" from the @ - perhaps by
  38. some
  39. other co-expression (call it "B") invoking the first via an @ [think about
  40. that for a moment, it's probably the confusing part!].  If B uses the
  41. infix @ - as in (say) "foo" @ A, then A will see its @ operator as "returning"
  42. the value "foo".
  43.  
  44. So, each co-expression sees @ as an operator that "invokes" another
  45. co-expression
  46. to produce a result.  The result can be produced in one of two ways:
  47.  
  48. (1) Since a co-expression is an expression, and since all expressions in Icon
  49.     produce results, there is an implicit transfer of the result of that
  50.     expression back to the invoking co-expression.  This is how most people
  51.     use co-expressions, as in:
  52.  
  53.        nextLabel := create "L" || seq()
  54.  
  55.     to produce a unique label whenever activated.  (Note that this can also
  56.     be done using a procedure, as in:
  57.  
  58.        procedure newLabel()
  59.           static suffix
  60.           initial suffix := 0
  61.           return "L" || (suffix +:= 1)
  62.        end
  63.  
  64.     but some people find the co-expression form simpler.  Also note that
  65.  
  66.        procedure newLabel2()
  67.           return "L" || seq()
  68.        end
  69.  
  70.     and
  71.  
  72.        procedure newLabel3()
  73.           suspend "L" || seq()
  74.        end
  75.  
  76.     do *not* perform the same function.)
  77.           
  78.  
  79. (2) A co-expression may explicitly return a value to a waiting co-expression
  80.     using the binary @ operator.  The explicit transfer of control used here
  81.     more closely matches the role of coroutines found in some other languages,
  82.     and is likely to be used only in situations where coroutines would be used
  83.     in those other languages.  However, useful situations for applying
  84. coroutines
  85.     are few and far between and almost always very complex situations.  It is
  86.     difficult to find simple examples where using coroutines is cleaner than
  87.     alternatives.
  88.  
  89.   
  90.  
  91. --
  92. Steve Wampler-  SOLIS Project, National Solar Observatory
  93. swampler@noao.edu
  94.